home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / bin / update-pciids < prev    next >
Encoding:
Text File  |  2010-11-26  |  2.8 KB  |  131 lines

  1. #!/bin/sh
  2.  
  3. # update-pciids.sh is licensed under the GNU General Public License
  4. # (GPL) version 2 or above.
  5. # Copyright (C) 2008-2010 Anibal Monsalve Salazar <anibal@debian.org>
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 2 of the License, or
  9. # (at your option) any later version.
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. # Please read the "COPYING" file in the archive root, or visit
  15. # http://www.gnu.org/licenses/gpl.html, for information about the GPL.
  16. #
  17. # This scipt is a rewrite of a script with the same name by
  18. # Martin Mares.
  19.  
  20. set -e
  21.  
  22. #URL="http://pci-ids.ucw.cz/pci.ids"
  23. URL="http://pciids.sourceforge.net/v2.2/pci.ids"
  24. FILE=/usr/share/misc/pci.ids
  25.  
  26. RM="/bin/rm"
  27. MV="/bin/mv"
  28. SED="/bin/sed"
  29. GREP="/bin/grep"
  30. ECHO="/bin/echo"
  31. CHMOD="/bin/chmod"
  32. CHOWN="/bin/chown"
  33. GUNZIP="/bin/gunzip"
  34. BUNZIP2="/bin/bunzip2"
  35. TOUCH="/usr/bin/touch"
  36. WGET="/usr/bin/wget"
  37. CURL="/usr/bin/curl"
  38. LYNX="/usr/bin/lynx"
  39.  
  40. NEWFILE="$FILE.new"
  41. OLDFILE="$FILE.old"
  42.  
  43. if [ "$1" = "-q" ]
  44. then
  45.     quiet="yes"
  46. else
  47.     quiet="no"
  48. fi
  49.  
  50. if ! $TOUCH $NEWFILE > /dev/null 2>&1
  51. then
  52.     $ECHO >&2 "update-pciids: $NEWFILE is read-only"
  53.     exit 1
  54. fi
  55.  
  56. [ -f $NEWFILE ]     && $RM $NEWFILE
  57. [ -f $NEWFILE.bz2 ] && $RM $NEWFILE.bz2
  58. [ -f $NEWFILE.gz ]  && $RM $NEWFILE.gz
  59.  
  60. if [ -x $BUNZIP2 ]
  61. then
  62.     EXT=".bz2"
  63.     UNZIP=$BUNZIP2
  64. elif [ -x $GUNZIP ]
  65. then
  66.     EXT=".gz"
  67.     UNZIP=$GUNZIP
  68. else
  69.     $ECHO >&2 "update-pciids: cannot find bunzip2 or gunzip"
  70.     exit 1
  71. fi
  72.  
  73. if [ -x $WGET ]
  74. then
  75.     $WGET -nv -O $NEWFILE$EXT $URL$EXT > /dev/null 2>&1
  76. elif [ -x $CURL ]
  77. then
  78.     $CURL -o $NEWFILE$EXT $URL$EXT > /dev/null 2>&1
  79. elif [ -x $LYNX ]
  80. then
  81.     $LYNX -source $URL$EXT > $NEWFILE$EXT
  82. else
  83.     $ECHO >&2 "update-pciids: cannot find wget, curl or lynx"
  84.     exit 1
  85. fi
  86.  
  87. $UNZIP < $NEWFILE$EXT > $NEWFILE
  88. $RM $NEWFILE$EXT
  89.  
  90. if ! $GREP > /dev/null "^C " $NEWFILE
  91. then
  92.     $ECHO >&2 "update-pciids: missing class info, probably truncated file"
  93.     exit 1
  94. fi
  95.  
  96. date=$( $GREP -E "^#[[:space:]]Date:[[:space:]]*" $NEWFILE 2> /dev/null | $SED "s/^#[[:space:]]Date:[[:space:]]*//" )
  97.  
  98. if [ -z "$date" ]
  99. then
  100.     $ECHO >&2 "update-pciids: missing snapshot date, probably truncated file"
  101.     exit 1
  102. fi 
  103.  
  104. if [ -f $FILE ]
  105. then
  106.     $CHOWN --reference="$FILE" "$NEWFILE"
  107.     $CHMOD --reference="$FILE" "$NEWFILE"
  108.     [ -f $OLDFILE ] && $RM $OLDFILE
  109.     $MV $FILE $OLDFILE
  110. fi
  111.  
  112. $MV $NEWFILE $FILE
  113. $TOUCH -d "$date" $FILE
  114.  
  115. if [ -f $FILE.gz ]
  116. then
  117.     [ -f $OLDFILE.gz ] && $RM $OLDFILE.gz
  118.     $MV $FILE.gz $OLDFILE.gz
  119. fi
  120.  
  121. if [ $quiet = "no" ]
  122. then
  123.     $ECHO "Downloaded daily snapshot dated $date"
  124. fi
  125.  
  126. exit 0
  127.